package com.ddf.publics.service.impl;

import com.ddf.publics.entity.CommodityRecord;
import com.ddf.publics.dao.CommodityRecordDao;
import com.ddf.publics.entity.Page;
import com.ddf.publics.service.CommodityRecordService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 积分商品表(CommodityRecord)表服务实现类
 *
 * @author makejava
 * @since 2020-06-17 09:55:06
 */
@Service
public class CommodityRecordServiceImpl implements CommodityRecordService {
    @Resource
    private CommodityRecordDao commodityRecordDao;


    @Override
    public int exchange_count(Integer id) {
        return commodityRecordDao.exchange_count(id);
    }

    @Override
    public List<Map> exchange_list(Integer id, Page page) {
        if(page.getLimit()==null||page.getCount()==null){
            return null;
        }else {
            return commodityRecordDao.exchange_list(id,page.getLimit(),page.getCount());
        }

    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public CommodityRecord queryById(Integer id) {
        return this.commodityRecordDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<CommodityRecord> queryAllByLimit(int offset, int limit) {
        return this.commodityRecordDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param commodityRecord 实例对象
     * @return 实例对象
     */
    @Override
    public CommodityRecord insert(CommodityRecord commodityRecord) {
        this.commodityRecordDao.insert(commodityRecord);
        return commodityRecord;
    }

    /**
     * 修改数据
     *
     * @param commodityRecord 实例对象
     * @return 实例对象
     */
    @Override
    public CommodityRecord update(CommodityRecord commodityRecord) {
        this.commodityRecordDao.update(commodityRecord);
        return this.queryById(commodityRecord.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.commodityRecordDao.deleteById(id) > 0;
    }
}